﻿using System;
using System.Collections.Generic;

namespace FDSimpleModelGenerator.Common
{
    /// <summary>
    ///  异常抛出工厂
    /// </summary>
    public sealed class ExceptionThrowFactory : IExceptionThrowFactory
    {
        /// <summary>
        /// 抛出异常
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="msg"></param>
        /// <param name="innException"></param>
        public void Throw<E>(string msg, Exception innException = null) where E : Exception //, new()
        {
            var ex = default(E);
            if (innException == null)
            {
                ex = ExpressionAgent.Current.CreateInstance<E>(msg);
            }
            else
            {
                ex = ExpressionAgent.Current.CreateInstance<E>(msg, innException);
            }

            throw ex;
        }

    }
}
